<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
</head>
<body>
    <h1>请登录</h1>
    账号：<input type="text" id="username" value="admin"><br>
    密码：<input type="password" id="password" value="123456"><br>
    记住我：<input type="checkbox" id="rememberMe"><br>
    <input type="button" value="提交" onclick="login()">
</body>
</html>
<script>
    function login() {
        var httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
        var username = document.getElementById('username').value;
        var password = document.getElementById('password').value;
        var rememberMe = document.getElementById('rememberMe').checked;

        var url = '/user/login?username='+username+'&password='+password+'&rememberMe='+rememberMe;
        httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"./Ptest.php?name=test&nameone=testone"
        httpRequest.send();//第三步：发送请求  将请求参数写在URL中

        //获取数据后的处理程序
        httpRequest.onreadystatechange = function () {
            if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                var json = httpRequest.responseText;//获取到json字符串，还需解析
                var res = JSON.parse(json);
                if (res.code == 200){
                    window.location.href = '/index';
                }else {
                    alert(res.msg);
                }
            }
        };
    }
</script>